home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP04.ZIP / CHAP04 / DKOALA / KOALA.H < prev    next >
C/C++ Source or Header  |  1993-04-13  |  3KB  |  95 lines

  1. /*
  2.  * KOALA.H
  3.  *
  4.  * Classes that implement the Koala object independent of whether
  5.  * we live in a DLL or EXE.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Right Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #ifndef _KOALA_H_
  18. #define _KOALA_H_
  19.  
  20.  
  21. #include <windows.h>
  22. #include <ole2.h>       //ole2.h has IPersist, compobj.h doesn't
  23.  
  24. //This defines all GUIDs used in this book so we can track them easily.
  25. #include <bookguid.h>
  26.  
  27.  
  28. //Type for an object-destroyed callback
  29. typedef void (FAR PASCAL *LPFNDESTROYED)(void);
  30.  
  31.  
  32.  
  33. /*
  34.  * The Koala object is implemented in its own class with its own
  35.  * IUnknown to support aggregation.  It contains one CImpIPersist
  36.  * object that we use to implement the externally exposed interfaces.
  37.  */
  38.  
  39. class __far CKoala : public IUnknown
  40.     {
  41.     //Make any contained interfaces your friends so they can get at you
  42.     friend class CImpIPersist;
  43.  
  44.     protected:
  45.         ULONG           m_cRef;         //Object reference count.
  46.         LPUNKNOWN       m_punkOuter;    //Controlling Unknown for aggregation
  47.  
  48.         LPFNDESTROYED   m_pfnDestroy;   //Function to call on closure.
  49.         LPPERSIST       m_pIPersist;    //Contained interface implemetation
  50.  
  51.     public:
  52.         CKoala(LPUNKNOWN, LPFNDESTROYED);
  53.         ~CKoala(void);
  54.  
  55.         BOOL FInit(void);
  56.  
  57.         //Non-delegating object IUnknown
  58.         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);
  59.         STDMETHODIMP_(ULONG) AddRef(void);
  60.         STDMETHODIMP_(ULONG) Release(void);
  61.     };
  62.  
  63. typedef CKoala FAR * LPCKoala;
  64.  
  65.  
  66. /*
  67.  * Interface implementations for the CKoala object.
  68.  */
  69.  
  70. class __far CImpIPersist : public IPersist
  71.     {
  72.     private:
  73.         ULONG           m_cRef;         //Interface reference count.
  74.         LPVOID          m_pObj;         //Back pointer to the object.
  75.         LPUNKNOWN       m_punkOuter;    //Controlling unknown for delegation
  76.  
  77.     public:
  78.         CImpIPersist(LPVOID, LPUNKNOWN);
  79.         ~CImpIPersist(void);
  80.  
  81.         //IUnknown members that delegate to m_punkOuter.
  82.         STDMETHODIMP         QueryInterface(REFIID, LPVOID FAR *);
  83.         STDMETHODIMP_(ULONG) AddRef(void);
  84.         STDMETHODIMP_(ULONG) Release(void);
  85.  
  86.         //IPersist members
  87.         STDMETHODIMP         GetClassID(LPCLSID);
  88.     };
  89.  
  90.  
  91. typedef CImpIPersist FAR * LPIMPIPERSIST;
  92.  
  93.  
  94. #endif //_KOALA_H_
  95.